home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0169_UnixTimeDate Conversion (Delphi).pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-08-30  |  1.8 KB  |  58 lines

  1. {
  2.  
  3. Here's another Unit from me, This time it's a 
  4.  Unix to DelphiTimeDate and ViceVersa Conversion Routines...
  5.  
  6. Andre Jakobs
  7.   MicroBrain Technologies Inc.
  8.     The Netherlands
  9.  
  10. unit U_DateTime;
  11. {
  12.  written by Andre Jakobs  from  MicroBrain Technologies Inc.
  13.  
  14.  
  15. This Unit Converts UNIX timestamps and Delphi timestamps
  16.  
  17. Unix stores the TimeDate in a four byte long-integer(DoubleWord), As
  18. the number of seconds since 1-januari-1970 0:0:0 .....
  19.  
  20. Delphi stores the TimeDate in TDateTime (a Float), where the integer
  21. part of TDateTime type is the Number of days since 1-januari-0001 0:0:0
  22. and the floating-point part the fractional Part of the day}
  23.  
  24. interface
  25.  
  26. const
  27.     UnixStartDate : tdatetime = 719163.0;
  28.  
  29. function DelphiDateTimeToUnix(ConvDate:TdateTime):longint;
  30. function UnixToDelphiDateTime(USec:longint):TDateTime;
  31.  
  32. implementation
  33.  
  34. (*-----------------------------------------------------------*)
  35. (*         D e l p h i D a t e T i m e T o U N I X           *)
  36. (*-----------------------------------------------------------*)
  37. function DelphiDateTimeToUnix(ConvDate:TdateTime):longint;
  38. {Converts Delphi TDateTime to Unix seconds,
  39.    ConvDate = the Date and Time that you want to convert
  40.    example:   UnixSeconds:=DelphiDateTimeToUnix(Now);}
  41. begin
  42.   Result:=round((ConvDate-UnixStartDate)*86400);
  43.  end;
  44.  
  45. (*-----------------------------------------------------------*)
  46. (*         U N I X T o D e l p h i D a t e T i m e           *)
  47. (*-----------------------------------------------------------*)
  48. function UnixToDelphiDateTime(USec:longint):TDateTime;
  49. {Converts Unix seconds to Delphi TDateTime,
  50.    USec = the Unix Date Time that you want to convert
  51.    example:  DelphiTimeDate:=UnixToDelphiTimeDate(693596);}
  52. begin
  53.   Result:=(Usec/86400)+UnixStartDate;
  54.  end;
  55.  
  56. end.
  57.  
  58.